package com.changli07.encapsulation;

public class exer1 {
    public static void main(String[] args) {
        //    exer1 test = new exer1();
        Person p1 = new Person();
        p1.setAge(20);
        System.out.println(p1.getAge());
    }
}
class Person {
    private int age;
    public void setAge(int age) {
        if(age>0&&age<120){
            this.age = age;
        }
        else {
            System.out.println("您输入的年龄不合法!");
        }
    }
    public int getAge() {
        return this.age;
    }
}
